﻿package adapter
{
	public class PointToDistance
	{
													//----------------------------------------------API------------------------------------
													//================ Properties ===============
													
													//================ Constants ================

													//================ Constructor ==============
		public function PointToDistance():void
		{
		}													
													//================ Public Methods ===========
		public function trans(aVal:Array):Array
		{
			var resultArr:Array=new Array();
			var xArr:Array=new Array();
			var yArr:Array=new Array();		
			for(var i:int=0;i<aVal.length-1;i++)
			{
				var dietX:Number=Number(FormatNumber(aVal[i+1].x-aVal[i].x,2));
				var dietY:Number=Number(FormatNumber(aVal[i+1].y-aVal[i].y,2));
				xArr.push(dietX);
				yArr.push(dietY);
			}
			resultArr.push(xArr,yArr);		
			return resultArr;
		}
													//----------------------------------------------private--------------------------------
													
													//================ Properties ===============
	
													//================ Private Methods ==========
		private function FormatNumber(num:Number,nAfterDot:int):String
		{
		  var srcStr:String;
		  var resultStr:String
		  var dotPos:int;
		  srcStr=(num).toString();
		  srcStr = ""+srcStr+"";
		  var strLen:uint = srcStr.length;
		  dotPos = srcStr.indexOf(".",0);
		  if (dotPos == -1){
		    resultStr = srcStr+".";
		    for (var i:uint=0;i<nAfterDot;i++){
		    resultStr = resultStr+"0";
		    }
		    return resultStr;
		  }else{
		    if ((strLen - dotPos - 1) >= nAfterDot){
		    var nAfter:int = dotPos + nAfterDot + 1;
		    var nTen:int =1;
		    for(var j:uint=0;j<nAfterDot;j++){
		      nTen = nTen*10;
		    }
		    var resultnum:Number=Math.round(num*nTen)/nTen;
		    resultStr = resultnum.toString();
		    return resultStr;
		    }else{
		    resultStr = srcStr;
		    for (i=0;i<(nAfterDot - strLen + dotPos + 1);i++){
		      resultStr = resultStr+"0";
		    }
		    return resultStr;
		    }
		  }
	  }
													//================ Destroy ==================
	}
}